package com.example.excelimport.util;

import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy;
import org.apache.poi.ss.usermodel.Cell;

import java.util.List;

public class CustomColumnWidthStyleStrategy extends AbstractColumnWidthStyleStrategy {
    @Override
    protected void setColumnWidth(WriteSheetHolder writeSheetHolder, List<WriteCellData<?>> cellDataList,
                                  Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
        if (isHead) {
            // 表头列宽
            writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(), 4000);
        } else {
            // 数据列宽
            writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(), 6000);
        }
    }
}

